
package com.joysuch.wwyt.datadump.biz.convertor;

import cn.zlg.common.datadump.annotation.DataDumpField;
import cn.zlg.common.datadump.convertor.FieldValueConvert;
import cn.zlg.common.datadump.service.JPABatchQueryPropertyValueService;
import com.joysuch.wwyt.bp.entity.BpDepart;
import com.joysuch.wwyt.bp.entity.dsl.QBpDepart;
import com.joysuch.wwyt.bp.repository.BpDepartDao;
import com.joysuch.wwyt.core.entity.BaseTypeGroupItem;
import com.joysuch.wwyt.core.entity.dsl.QBaseTypeGroupItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

@Component
public class ExportGetDepartNameByIdConvertor implements FieldValueConvert<Long, String> {
    @Autowired
    private BpDepartDao departDao;
    @Autowired
    private JPABatchQueryPropertyValueService<BpDepart,Long,String> batchQueryService;

    @Override
    public String convert(Object bean, Long value, DataDumpField dataField) {
        if (value == null) {
            return null;
        }
        return departDao.getNameById((Long) value);
    }

    @Override
    public boolean supportBatch() {
        return true;
    }

    @Override
    public List<String> convert(List<Object> bean, List<Long> value, DataDumpField dataDumpField) {
        if(value == null || value.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        QBpDepart q = QBpDepart.bpDepart1;
        return batchQueryService.query(q, q.id, q.name, value);
    }
}
